/* Npcs */
instance DIEB (NPC_DEFAULT)
{
	name 		= "DIEB";
	guild		= GIL_NONE;
	id			= 1;
	voice		= 13;
	level		= 554;
	Npctype		= NPCTYPE_MAIN;
	attribute[ATR_STRENGTH] 		= 3;
	attribute[ATR_DEXTERITY] 		= 3;
	attribute[ATR_MANA_MAX] 		= 3;
	attribute[ATR_MANA] 			= 3;
	attribute[ATR_HITPOINTS_MAX]	= 3;
	attribute[ATR_HITPOINTS] 		= 3;
	Mdl_SetVisual (self,"HUMANS.MDS");
	Mdl_SetVisualBody (self, "hum_body_Naked0", 9,0,"Hum_Head_Pony",FACE_N_Player,0,NO_ARMOR);
	Mdl_ApplyOverlayMDS(self, "HUMANS_SPRINT.MDS");
	B_SetFightSkills 	(self, 0);
	
	start_aistate = ZS_STAND_WP;
};
instance ANDERER (NPC_DEFAULT)
{
	name 		= "ANDERER";
	guild		= GIL_KDF;
	id			= 34;
	voice		= 11;
	level		= 2;
	Npctype		= NPCTYPE_MAIN;
	attribute[ATR_STRENGTH] 		= 7;
	attribute[ATR_DEXTERITY] 		= 7;
	attribute[ATR_MANA_MAX] 		= 7;
	attribute[ATR_MANA] 			= 7;
	attribute[ATR_HITPOINTS_MAX]	= 7;
	attribute[ATR_HITPOINTS] 		= 7;
	Mdl_SetVisual (self,"HUMANS.MDS");
	Mdl_SetVisualBody (self, "hum_body_Naked0", 2,0,"Hum_Head_Thief",FACE_N_Player+2,0,ITAR_DEMENTOR);
	Mdl_ApplyOverlayMDS(self, "HUMANS_RELAXED.MDS");
	B_SetFightSkills 	(self, 120);
	
	start_aistate = ZS_STAND_WP;
};


/* Konstanten */
const int AIV_Her_Player = 99;
const int oCNpc_length = 2564; // 0x0A04

const int F1 = 59; // 0x3B
const int F2 = 60; // 0x3C

/* Funktionen */
func void _MP_SetPlayer(var int w_ptr, var int r_ptr, var int len) {
	var int pos;
	var int clen;
	Print("Gehe in loop!");
	pos = MEM_StackPos.position;
		if(clen >= 20) { //&&clen < 648&&clen > 1048) {
			MEM_WriteInt(w_ptr, MEM_ReadInt(r_ptr));
		};		
		w_ptr += 4;
		r_ptr += 4;
		clen  += 4;
		if(clen < len) {
	MEM_StackPos.position = pos; };
	Print("Fertig!");
};

func void MP_SetPlayer(var int n, var int _n, var int by) {
	var oCNpc oth; oth = Hlp_GetNpc(n);
	var oCNpc slf; slf = Hlp_GetNpc(PC_Hero);
	var oCNpc old; old = Hlp_GetNpc(_n);
	
	hero.aivar[AIV_Her_Player] = Hlp_GetInstanceID(oth);
	
	var int oth_ptr; oth_ptr = MEM_SearchVobByName(oth._zCObject_objectName);
	var int slf_ptr; slf_ptr = MEM_SearchVobByName(slf._zCObject_objectName);
	var int old_ptr; old_ptr = MEM_SearchVobByName(old._zCObject_objectName);
	
	if(!by) {
		_MP_SetPlayer(old_ptr, slf_ptr, oCNpc_length);
	};
	_MP_SetPlayer(slf_ptr, oth_ptr, oCNpc_length);
	/* if(!by) {
		MEM_AssignInst (old, slf_ptr);
	};
	MEM_AssignInst (slf, oth_ptr); */
	
	var C_Npc oth_c; oth_c = Hlp_GetNpc(n);
	AI_Teleport(oth_c, "TOT");
};

/* Loop Funktion */
func void MP_Loop() {
	MEM_KeyState(F1);
	MEM_KeyState(F2);
	if(MEMINT_KeyState[F1] == KEY_PRESSED&&hero.aivar[AIV_Her_Player] != DIEB) {
		MP_SetPlayer(DIEB, ANDERER, 0);
	};
	if(MEMINT_KeyState[F2] == KEY_PRESSED&&hero.aivar[AIV_Her_Player] != ANDERER) {
		MP_SetPlayer(ANDERER, DIEB, 0);
	};
	Wld_SendTrigger("MP_LOOP_TRIGGER");
};

/* Init Kram */
func void MP_Init(var int n, var int _n) {
	MEM_InitGlobalInst();
	MEM_InitLabels();
	
	MP_SetPlayer(DIEB, -1, 1);
	
	hero.aivar[AIV_Her_Player] = n;
	MP_Loop();
};

/**** ENDE ****/
